package com.binance.mbxgateway.web.utils;

import java.util.Calendar;
import java.util.Date;

public class CalendarUtils {

    public static Calendar getTimelessToday() {
        Calendar timelessToday = Calendar.getInstance();
        timelessToday.set(Calendar.HOUR_OF_DAY, 0);
        timelessToday.set(Calendar.MINUTE, 0);
        timelessToday.set(Calendar.SECOND, 0);
        timelessToday.set(Calendar.MILLISECOND, 0);

        return timelessToday;
    }

    public static Date getDateBefore(Date d, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.set(Calendar.HOUR_OF_DAY, 0);
        now.set(Calendar.MINUTE, 0);
        now.set(Calendar.SECOND, 0);
        now.set(Calendar.MILLISECOND, 0);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        return now.getTime();
    }

    public static Calendar getTimelessTmr() {
        Calendar timelessTmr = Calendar.getInstance();
        timelessTmr.add(Calendar.DAY_OF_YEAR, 1);
        timelessTmr.set(Calendar.HOUR_OF_DAY, 0);
        timelessTmr.set(Calendar.MINUTE, 0);
        timelessTmr.set(Calendar.SECOND, 0);
        timelessTmr.set(Calendar.MILLISECOND, 0);

        return timelessTmr;
    }

    public static Date removeMillis(Date date) {
        if (date == null)
            return null;
        Calendar time = Calendar.getInstance();
        time.setTime(date);
        time.set(Calendar.MILLISECOND, 0);
        return time.getTime();

    }
}
